﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Ken_WPF_UI.View
{
    /// <summary>
    /// ImageWindow.xaml 的交互逻辑
    /// </summary>
    public partial class ImageWindow : Window
    {
        public ImageWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //this.imagePic.Source = new BitmapImage(new Uri("/Images/avatar.png", UriKind.Relative));

            // pack URI  application代表程序源的授权  application:///  已知的程序里面的资源文件路径
            //pack URI  siteoforigin   siteoforigin:///   需要把程序里面的资源 属性 生成操作设置为内容，并把复制到输出目录的“不复制” 设置为其他项（后置局限性大 前者没局限性）
            //this.imagePic.Source = new BitmapImage(new Uri("pack://application:,,,/Assets/Images/avatar.png", UriKind.Absolute));//绝对路径
            //this.imagePic.Source = new BitmapImage(new Uri("pack://siteoforigin:,,,/Assets/Images/avatar.png", UriKind.Absolute));//绝对路径

            // 使用DataContent 绑定  前提 是页面针对的标签里面的Source需要写成{Binding}
            this.imagePic.DataContext = new BitmapImage(new Uri("pack://siteoforigin:,,,/Assets/Images/avatar.png", UriKind.Absolute));
        }

        //这个不知道怎么触发
        private void Image_SourceUpdated(object sender, DataTransferEventArgs e)
        {

            MessageBox.Show("图片资源已变更");

        }

        private void Image_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            MessageBox.Show("Image_DataContextChanged=>图片资源已变更");
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.imagePic.DataContext = new BitmapImage(new Uri("pack://application:,,,/Assets/Images/Logo.png", UriKind.Absolute));
        }
    }
}
